package com.vasthu.gui;

import java.util.*;
import javax.swing.table.*;

public class VstTableItemModel extends AbstractTableModel {

    private List<VstTableItemSelectable> dataList;
    private String[] header;
    private Class[] colClass;

    public VstTableItemModel(List<VstTableItemSelectable> dataList, String[] header, Class[] colClass) {
        this.dataList = dataList;
		this.header = header;
        this.colClass = colClass;
    }

    @Override
    public int getRowCount() {
        return dataList.size();
    }

    @Override
    public int getColumnCount() {
        return header.length;
    }
    
    @Override
    public Class getColumnClass(int colindex) {
        return colClass[colindex];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        VstTableItemSelectable item = getObjecAtRow(rowIndex);
		if (item != null) {
			return item.getValue(columnIndex);
		}
		return null;
    }

    @Override
    public String getColumnName(int index) {
        return header[index];
    }
    
    public VstTableItemSelectable getObjecAtRow(int index) {
        return dataList.get(index);
    }
	
	public void deleteRow(int row) {
		dataList.remove(row);
		fireTableRowsDeleted(row, row);
	}
	        
}